 MODULE SURFEXCDRIVERSAD_CTL_MOD
CONTAINS
SUBROUTINE SURFEXCDRIVERSAD_CTL( &
 &   KIDIA, KFDIA, KLON, KLEVS, KTILES, KSTEP &
 & , PTSTEP, PRVDIFTS &
 & , LDNOPERT, LDKPERTS, LDSURF2, LDREGSF, LDREGBUOF &
! input data, non-tiled
 & , KTVL, KTVH, PCVL, PCVH, PCUR &
 & , PLAIL, PLAIH &
 & , PSNM5 , PRSN5 &
 & , PUMLEV5, PVMLEV5 , PTMLEV5, PQMLEV5, PAPHMS5, PGEOMLEV5, PCPTGZLEV5 &
 & , PSST   , PTSKM1M5, PCHAR  , PSSRFL5, PTICE5 , PTSNOW5  &
 & , PWLMX5 &
 & , PUCURR5, PVCURR5 &
! input data, soil - trajectory
 & , PTSAM1M5, PWSAM1M5, KSOTY &
! input data, tiled - trajectory
 & , PFRTI, PALBTI5 &
!
 & , PSSDP2  , PSSDP3 &
 & , YDCST   , YDEXC   , YDVEG , YDSOIL , YDFLAKE, YDURB & 
! updated data, tiled - trajectory
 & , PUSTRTI5, PVSTRTI5, PAHFSTI5, PEVAPTI5, PTSKTI5 &
! updated data, non-tiled - trajectory
 & , PZ0M5, PZ0H5 &
! output data, tiled - trajectory
 & , PSSRFLTI5, PQSTI5 , PDQSTI5 , PCPTSTI5 &
 & , PCFHTI5  , PCFQTI5, PCSATTI5, PCAIRTI5 &
 & , PZ0MTIW5, PZ0HTIW5, PZ0QTIW5, PQSAPPTI5, PCPTSPPTI5, PBUOMTI5 &
! output data, non-tiled - trajectory
 & , PCFMLEV5, PEVAPSNW5 &
 & , PZ0MW5  , PZ0HW5    , PZ0QW5, PCPTSPP5, PQSAPP5, PBUOMPP5 &
! input data, non-tiled
 & , PUMLEV  , PVMLEV    , PTMLEV, PQMLEV  , PAPHMS , PGEOMLEV, PCPTGZLEV &
 & , PTSKM1M , PSSRFL    , PTICE , PTSNOW  &
! input data, soil
 & , PTSAM1M , PWSAM1M &
! input data, tiled
 & , PALBTI &
! updated data, tiled
 & , PUSTRTI , PVSTRTI , PAHFSTI, PEVAPTI, PTSKTI &
! updated data, non-tiled
 & , PZ0M, PZ0H &
! output data, tiled
 & , PSSRFLTI, PQSTI   , PDQSTI, PCPTSTI , PCFHTI, PCFQTI, PCSATTI, PCAIRTI &
 & , PZ0MTIW, PZ0HTIW, PZ0QTIW, PQSAPPTI, PCPTSPPTI, PBUOMTI &
! output data, non-tiled
 & , PCFMLEV , PEVAPSNW &
 & , PZ0MW   , PZ0HW    , PZ0QW, PCPTSPP , PQSAPP, PBUOMPP &
 & )

USE PARKIND1 , ONLY : JPIM, JPRB
USE YOMHOOK  , ONLY : LHOOK, DR_HOOK, JPHOOK
USE YOS_THF  , ONLY : R2ES, R3LES, R3IES, R4LES, R4IES, R5LES, R5IES
USE YOS_CST  , ONLY : TCST
USE YOS_EXC  , ONLY : TEXC
USE YOS_VEG  , ONLY : TVEG
USE YOS_SOIL , ONLY : TSOIL
USE YOS_FLAKE, ONLY : TFLAKE
USE YOS_URB  , ONLY : TURB
USE VUPDZ0_MOD
USE VUPDZ0S_MOD
USE VSURFS_MOD
USE VEXCSS_MOD
USE VEVAPS_MOD
USE VUPDZ0SAD_MOD
USE VSURFSAD_MOD
USE VEXCSSAD_MOD
USE VEVAPSAD_MOD

! (C) Copyright 2005- ECMWF.
!
! This software is licensed under the terms of the Apache Licence Version 2.0
! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
! In applying this licence, ECMWF does not waive the privileges and immunities
! granted to it by virtue of its status as an intergovernmental organisation
! nor does it submit to any jurisdiction.

!------------------------------------------------------------------------

!  PURPOSE:
!    Routine SURFEXCDRIVERSAD controls the ensemble of routines that prepare
!    the surface exchange coefficients and associated surface quantities
!    needed for the solution of the vertical diffusion equations. 
!    (Adjoint)

!  SURFEXCDRIVERSAD is called by VDFMAINSAD

!  METHOD:
!    This routine is only a shell needed by the surface library
!    externalisation.

!  AUTHOR:
!    M. Janiskova       ECMWF July 2005  

!  REVISION HISTORY:
!    A. Beljaars        ECMWF Dec 2005    TOFD
!    M. Janiskova  10/04/2006 Calls for AD surface routines
!    G. Balsamo    10/07/2006 Add soil type
!    M. Janiskova  21/05/2007 clean-up of roughness length initialization
!    S. Boussetta/G.Balsamo May 2009 Add lai
!    M. Janiskova  May 2012->2013 Modified computation of snow evaporation
!                             Perturbation of top layer surface fields
!    P. Lopez      June 2015  Added regularization of wet skin tile
!                             perturbation in low wind situations.
!    J. McNorton   24/08/2022 urban tile
!    P. Lopez      July 2025  Added ocean currents (trajectory only)
!    P. Lopez      July 2025  Added optional (LDREGBUOF) extra regularization 
!                             when surface buoyancy flux is very small.

!  INTERFACE: 

!    Integers (In):
!      KIDIA    :    Begin point in arrays
!      KFDIA    :    End point in arrays
!      KLON     :    Length of arrays
!      KLEVS    :    Number of soil layers
!      KTILES   :    Number of tiles
!      KSTEP    :    Time step index
!      KTVL     :    Dominant low vegetation type
!      KTVH     :    Dominant high vegetation type
!      KSOTY    :    SOIL TYPE                                       (1-7)

!    Reals (In):
!      PTSTEP   :    Timestep
!      PRVDIFTS :    Semi-implicit factor for vertical diffusion discretization
!      PCVL     :    LOW VEGETATION COVER                          -  
!      PCVH     :    HIGH VEGETATION COVER
!      PCUR     :    URBAN COVER                                   -
!      PLAIL    :    LAI of low vegetation
!      PLAIH    :    LAI of High vegetation                       -  

!  Logical:
!      LDNOPERT :    TRUE when no perturbations is required for surface arrays
!      LDKPERTS :    TRUE when pertubations of exchange coefficients are used
!      LDSURF2  :    TRUE when simplified surface scheme called
!      LDREGSF  :    TRUE when regularization used
!      LDREGBUOF:    TRUE for extra regularization when surface buoyancy flux is very small

!*      Reals with tile index (In): 
!  Trajectory  Perturbation  Description                               Unit
!  PFRTI       ---           TILE FRACTIONS                            (0-1)
!                            1: WATER         5: SNOW ON LOW-VEG+BARE-SOIL
!                            2: ICE           6: DRY SNOW-FREE HIGH-VEG
!                            3: WET SKIN      7: SNOW UNDER HIGH-VEG
!                            4: DRY SNOW-FREE 8: BARE SOIL
!                               LOW-VEG
!  PALBTI5     PALBTI        Tile albedo                               (0-1)

!*      Reals independent of tiles (In):
!  Trajectory  Perturbation  Description                               Unit
!  PUMLEV5     PUMLEV        X-VELOCITY COMPONENT, lowest              m/s
!                            atmospheric level
!  PVMLEV5     PVMLEV        Y-VELOCITY COMPONENT, lowest              m/s
!                            atmospheric level
!  PTMLEV5     PTMLEV        TEMPERATURE, lowest atmospheric level     K
!  PQMLEV5     PQMLEV        SPECIFIC HUMIDITY                         kg/kg
!  PAPHMS5     PAPHMS        Surface pressure                          Pa
!  PGEOMLEV5   PGEOMLEV      Geopotential, lowest atmospehric level    m2/s2
!  PCPTGZLEV5  PCPTGZLEV     Geopotential, lowest atmospehric level    J/kg
!  PSST        ---           (OPEN) SEA SURFACE TEMPERATURE            K
!  PTSKM1M5    PTSKM1M       SKIN TEMPERATURE                          K
!  PCHAR       ---           "EQUIVALENT" CHARNOCK PARAMETER           -
!  PSSRFL5     PSSRFL        NET SHORTWAVE RADIATION FLUX AT SURFACE   W/m2
!  PTSAM1M5    PTSAM1M       SURFACE TEMPERATURE                       K
!  PWSAM1M5    PWSAM1M       SOIL MOISTURE ALL LAYERS                 m**3/m**3
!  PTICE5      PTICE         Ice temperature, top slab                 K
!  PTSNOW5     PTSNOW        Snow temperature                          K
!  PWLMX5      ---           Maximum interception layer capacity       kg/m**2
!  PUCURR5     ---           Ocean current U-component                 m/s
!  PVCURR5     ---           Ocean current V-component                 m/s

!*      Reals with tile index (In/Out):
!  Trajectory  Perturbation  Description                               Unit
!  PUSTRTI5    PUSTRTI       SURFACE U-STRESS                          N/m2
!  PVSTRTI5    PVSTRTI       SURFACE V-STRESS                          N/m2
!  PAHFSTI5    PAHFSTI       SURFACE SENSIBLE HEAT FLUX                W/m2
!  PEVAPTI5    PEVAPTI       SURFACE MOISTURE FLUX                     KG/m2/s
!  PTSKTI5     PTSKTI        SKIN TEMPERATURE                          K

!*      Reals independent of tiles (In/Out):
!  Trajectory  Perturbation  Description                               Unit
!  PZ0M5       PZ0M          AERODYNAMIC ROUGHNESS LENGTH              m
!  PZ0H5       PZ0H          ROUGHNESS LENGTH FOR HEAT                 m

!*      Reals with tile index (Out):
!  Trajectory  Perturbation  Description                               Unit
!  PSSRFLTI5   PSSRFLTI      Tiled NET SHORTWAVE RADIATION FLUX        W/m2
!                            AT SURFACE
!  PQSTI5      PQSTI         Tiled SATURATION Q AT SURFACE             kg/kg
!  PDQSTI5     PDQSTI        Tiled DERIVATIVE OF SATURATION Q-CURVE    kg/kg/K
!  PCPTSTI5    PCPTSTI       Tiled DRY STATIC ENERGY AT SURFACE        J/kg
!  PCFHTI5     PCFHTI        Tiled EXCHANGE COEFFICIENT AT THE SURFACE ????
!  PCFQTI5     PCFQTI        Tiled EXCHANGE COEFFICIENT AT THE SURFACE ????
!  PCSATTI5    PCSATTI       MULTIPLICATION FACTOR FOR QS AT SURFACE   -
!                            FOR SURFACE FLUX COMPUTATION
!  PCAIRTI5    PCAIRTI       MULTIPLICATION FACTOR FOR Q AT LOWEST     - 
!                            MODEL LEVEL FOR SURFACE FLUX COMPUTATION

!*      Reals independent of tiles (Out):
!  Trajectory  Perturbation  Description                               Unit
!  PCFMLEV5    PCFMLEV       PROP. TO EXCH. COEFF. FOR MOMENTUM        ????
!                             (C-STAR IN DOC.) (SURFACE LAYER ONLY)
!  PEVAPSNW5   PEVAPSNW      Evaporation from snow under forest        kgm-2s-1
!  PZ0MW5      PZ0MW         Roughness length for momentum,WMO station m
!  PZ0HW5      PZ0HW         Roughness length for heat, WMO station    m
!  PZ0QW5      PZ0QW         Roughness length for moisture,WMO station m
!  PCPTSPP5    PCPTSPP       Cp*Ts for post-processing of weather      J/kg
!                            parameters
!  PQSAPP5     PQSAPP        Apparent surface humidity                 kg/kg
!                            post-processing of weather parameters
!  PBUOMPP5    PBUOMPP       Buoyancy flux, for post-processing        ???? 
!                            of gustiness

!     EXTERNALS.
!     ----------

!     ** SURFEXCDRIVERSAD_CTL CALLS SUCCESSIVELY:
!         *VUPDZ0*
!         *VSURF*
!         *VEXCS*
!         *VEVAP*

!  DOCUMENTATION:
!    See Physics Volume of IFS documentation

!------------------------------------------------------------------------

IMPLICIT NONE

! Declaration of arguments

INTEGER(KIND=JPIM),INTENT(IN)    :: KIDIA
INTEGER(KIND=JPIM),INTENT(IN)    :: KFDIA
INTEGER(KIND=JPIM),INTENT(IN)    :: KLON
INTEGER(KIND=JPIM),INTENT(IN)    :: KLEVS
INTEGER(KIND=JPIM),INTENT(IN)    :: KTILES
INTEGER(KIND=JPIM),INTENT(IN)    :: KSTEP
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSTEP
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRVDIFTS
LOGICAL           ,INTENT(IN)    :: LDNOPERT
LOGICAL           ,INTENT(IN)    :: LDKPERTS
LOGICAL           ,INTENT(IN)    :: LDSURF2
LOGICAL           ,INTENT(IN)    :: LDREGSF
LOGICAL           ,INTENT(IN)    :: LDREGBUOF

INTEGER(KIND=JPIM),INTENT(IN)    :: KTVL(:) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KTVH(:) 
INTEGER(KIND=JPIM),INTENT(IN)    :: KSOTY(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCVL(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCVH(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCUR(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLAIL(KLON) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PLAIH(KLON)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSNM5(:,:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PRSN5(:,:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUMLEV5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVMLEV5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTMLEV5(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PQMLEV5(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PAPHMS5(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PGEOMLEV5(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCPTGZLEV5(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSST(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSKM1M5(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PCHAR(:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSSRFL5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTICE5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSNOW5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWLMX5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PUCURR5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PVCURR5(:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PTSAM1M5(:,:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PWSAM1M5(:,:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PFRTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PALBTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSSDP2(:,:)
REAL(KIND=JPRB)   ,INTENT(IN)    :: PSSDP3(:,:,:)
TYPE(TCST)        ,INTENT(IN)    :: YDCST
TYPE(TEXC)        ,INTENT(IN)    :: YDEXC
TYPE(TVEG)        ,INTENT(IN)    :: YDVEG
TYPE(TSOIL)       ,INTENT(IN)    :: YDSOIL
TYPE(TFLAKE)      ,INTENT(IN)    :: YDFLAKE
TYPE(TURB)        ,INTENT(IN)    :: YDURB
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUSTRTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVSTRTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAHFSTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEVAPTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTSKTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0M5(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0H5(:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PSSRFLTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQSTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PDQSTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCPTSTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCFHTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCFQTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCSATTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCAIRTI5(:,:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCFMLEV5(:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PEVAPSNW5(:) 
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PZ0MW5(:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PZ0HW5(:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PZ0QW5(:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCPTSPP5(:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQSAPP5(:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PBUOMPP5(:)
! Tile dependent pp
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PZ0MTIW5(:,:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PZ0HTIW5(:,:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PZ0QTIW5(:,:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PQSAPPTI5(:,:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PCPTSPPTI5(:,:)
REAL(KIND=JPRB)   ,INTENT(OUT)   :: PBUOMTI5(:,:)

REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUMLEV(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVMLEV(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTMLEV(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQMLEV(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAPHMS(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PGEOMLEV(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCPTGZLEV(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTSKM1M(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSSRFL(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTICE(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTSNOW(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTSAM1M(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PWSAM1M(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PALBTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PUSTRTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PVSTRTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PAHFSTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEVAPTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PTSKTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0M(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0H(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PSSRFLTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQSTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PDQSTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCPTSTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCFHTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCFQTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCSATTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCAIRTI(:,:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCFMLEV(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PEVAPSNW(:) 
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0MW(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0HW(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PZ0QW(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PCPTSPP(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PQSAPP(:)
REAL(KIND=JPRB)   ,INTENT(INOUT) :: PBUOMPP(:)
! Tile dependent pp
REAL(KIND=JPRB)   ,INTENT(INOUT)   :: PZ0MTIW(:,:)
REAL(KIND=JPRB)   ,INTENT(INOUT)   :: PZ0HTIW(:,:)
REAL(KIND=JPRB)   ,INTENT(INOUT)   :: PZ0QTIW(:,:)
REAL(KIND=JPRB)   ,INTENT(INOUT)   :: PQSAPPTI(:,:)
REAL(KIND=JPRB)   ,INTENT(INOUT)   :: PCPTSPPTI(:,:)
REAL(KIND=JPRB)   ,INTENT(INOUT)   :: PBUOMTI(:,:)

! Local variables

INTEGER(KIND=JPIM) :: IFRMAX(KLON), IFRLMAX(KLON)

REAL(KIND=JPRB) :: ZZ0MTI5(KLON,KTILES) , ZZ0HTI5(KLON,KTILES) ,&
                 & ZZ0QTI5(KLON,KTILES) , ZBUOMTI5(KLON,KTILES),&
                 & ZZDLTI5(KLON,KTILES) , ZRAQTI5(KLON,KTILES) ,&
                 & ZQSATI5(KLON,KTILES) , ZCFMTI5(KLON,KTILES) ,&
                 & ZZQSATI5(KLON,KTILES), ZTSA5(KLON,KTILES)
REAL(KIND=JPRB) :: ZZ0MTI55(KLON,KTILES)

REAL(KIND=JPRB) :: ZFRMAX5(KLON) , ZALB5(KLON)  , ZSSRFL15(KLON) , &
                 & ZSRFD5(KLON)  , ZWETL5(KLON) , ZWETH5(KLON)   , &
                 & ZWETHS5(KLON) , ZWETB5(KLON) , &
                 & ZCSNW5(KLON)  , &
                 & ZFRLMAX5(KLON)

REAL(KIND=JPRB) :: ZZ0MTI(KLON,KTILES) , ZZ0HTI(KLON,KTILES) ,&
                 & ZZ0QTI(KLON,KTILES) , ZBUOMTI(KLON,KTILES),&
                 & ZZDLTI(KLON,KTILES) , ZRAQTI(KLON,KTILES) ,&
                 & ZQSATI(KLON,KTILES) , ZCFMTI(KLON,KTILES) ,&
                 & ZZQSATI(KLON,KTILES)

REAL(KIND=JPRB) :: ZFRMAX(KLON)   , ZALB(KLON)     , ZSSRFL1(KLON)  , &
                 & ZSRFD(KLON)    , ZWETL(KLON)    , ZWETH(KLON)    , &
                 & ZWETHS(KLON)   , ZWETB(KLON)    , &
                 & ZTSA(KLON)     , ZCSNW(KLON)    , &
                 & ZFRLMAX(KLON)

!*            EXTRA LOCAL STORAGE FOR TRAJECTORY
!             ----- ----- ------- --- ----------

REAL(KIND=JPRB) :: ZZ0M55(KLON), ZQSSN5(KLON), ZQSSN15(KLON), ZCOR5(KLON)
REAL(KIND=JPRB) :: ZZ0H55(KLON)
REAL(KIND=JPRB) :: ZPSSRFLTI15(KLON,KTILES),ZPSSRFLTI25(KLON,KTILES)
REAL(KIND=JPRB) :: ZZSRFD5(KLON,KTILES),ZZQSATI55(KLON,KTILES)
REAL(KIND=JPRB) :: ZPCPTSTI5(KLON,KTILES)
REAL(KIND=JPRB) :: ZDIV15(KLON), ZDIV25(KLON), Z3S5(KLON), Z4S5(KLON)

REAL(KIND=JPRB) :: ZBLENDZ0
REAL(KIND=JPRB) :: ZCBLENDM(KLON), ZCBLENDM5(KLON), ZCBLENDH(KLON), ZCBLENDH5(KLON)

INTEGER(KIND=JPIM) :: JL, JTILE, KTILE

REAL(KIND=JPRB) :: ZQSSN, ZCOR, ZCONS1, ZZ0MWMO, ZZ0HWMO
REAL(KIND=JPRB) :: Z3S, Z4S
REAL(KIND=JPRB) :: ZDSN5(KLON)
REAL(KIND=JPRB) :: ZDSN(KLON)

REAL(KIND=JPHOOK) :: ZHOOK_HANDLE
LOGICAL         :: LLAND, LLSICE, LLHISSR(KLON)

#include "fcsttre.h"

!*         1.     Set up of general quantities
!                 ----------------------------

IF (LHOOK) CALL DR_HOOK('SURFEXCDRIVERSAD_CTL_MOD:SURFEXCDRIVERSAD_CTL',0,ZHOOK_HANDLE)
ASSOCIATE(RD=>YDCST%RD, RETV=>YDCST%RETV, RG=>YDCST%RG, RSIGMA=>YDCST%RSIGMA, &
 & RTT=>YDCST%RTT, &
 & REPDU2=>YDEXC%REPDU2, RKAP=>YDEXC%RKAP, RZ0ICE=>YDEXC%RZ0ICE, &
 & RALFMAXSN=>YDSOIL%RALFMAXSN, &
 & RVTRSR=>YDVEG%RVTRSR, LEURBAN=>YDURB%LEURBAN)

ZCONS1=1./(RG*PTSTEP)

!*         1.1  ESTIMATE SURF.FL. FOR STEP 0
!*              (ASSUME NEUTRAL STRATIFICATION)

IF ( KSTEP == 0) THEN
  DO JTILE=2,KTILES
    DO JL=KIDIA,KFDIA
      PTSKTI5 (JL,JTILE)=PTSKM1M5(JL)
    ENDDO
  ENDDO

  DO JL=KIDIA,KFDIA
    PTSKTI5(JL,1)=PSST(JL)
  ENDDO
ENDIF

! Total snow depth (m) 
ZDSN5(KIDIA:KFDIA) = SUM( PSNM5(KIDIA:KFDIA,:) / PRSN5(KIDIA:KFDIA,:),DIM=2) 

!ZZ0M55(KIDIA:KFDIA) = PZ0M5(KIDIA:KFDIA)
!ZZ0H55(KIDIA:KFDIA) = PZ0H5(KIDIA:KFDIA)

!*         1.2  UPDATE Z0
CALL VUPDZ0S(KIDIA,KFDIA,KLON,KTILES,KSTEP,&
 & KTVL, KTVH, PCVL, PCVH,PCUR,&
 & PUMLEV5 , PVMLEV5 ,&
 & PTMLEV5 , PQMLEV5 , PAPHMS5 , PGEOMLEV5,&
 & ZDSN5, &
 & PUSTRTI5, PVSTRTI5, PAHFSTI5, PEVAPTI5 ,&
 & PTSKTI5 , PCHAR   , PFRTI   ,&
 & PSSDP2  ,&
 & YDCST   , YDEXC   , YDVEG   , YDFLAKE  , YDURB  ,&
 & ZZ0MTI5 , ZZ0HTI5 , ZZ0QTI5 , ZBUOMTI5 , ZZDLTI5, ZRAQTI5,&
 & PUCURR5 , PVCURR5)


!*         1.3  FIND DOMINANT SURFACE TYPE parameters for postprocessing

ZFRMAX5(KIDIA:KFDIA) = PFRTI(KIDIA:KFDIA,1)
ZFRLMAX5(KIDIA:KFDIA) = PFRTI(KIDIA:KFDIA,1)
IFRMAX(KIDIA:KFDIA) = 1
IFRLMAX(KIDIA:KFDIA)=1
DO JTILE=2,KTILES
  DO JL=KIDIA,KFDIA
    IF (PFRTI(JL,JTILE)  >  ZFRMAX5(JL)) THEN
      ZFRMAX5(JL)= PFRTI(JL,JTILE)
      IFRMAX(JL) = JTILE
    ENDIF
    IF (PFRTI(JL,JTILE)  >  ZFRLMAX5(JL) .AND. &
      JTILE.NE.6 .AND. JTILE.NE.7) THEN
      ZFRLMAX5(JL)=PFRTI(JL,JTILE)
      IFRLMAX(JL)=JTILE
      IF (JTILE.EQ.3.OR.JTILE.EQ.9) THEN
!* for tiles wet-skin or lakes attribute if present
!* low-vegetation (4) if present or bare soil (8) 
         IF (PFRTI(JL,8).GT.0.0_JPRB) IFRLMAX(JL)=8
         IF (PFRTI(JL,4).GT.0.0_JPRB) IFRLMAX(JL)=4
      ENDIF
    ENDIF
  ENDDO
ENDDO

ZBLENDZ0=10._JPRB
ZCBLENDM5(KIDIA:KFDIA)=PFRTI(KIDIA:KFDIA,1)&
           &/(LOG(ZBLENDZ0/ZZ0MTI5(KIDIA:KFDIA,1)))**2
ZCBLENDH5(KIDIA:KFDIA)=PFRTI(KIDIA:KFDIA,1)&
           &/(LOG(ZBLENDZ0/ZZ0HTI5(KIDIA:KFDIA,1)))**2

DO JTILE=2,KTILES
  DO JL=KIDIA,KFDIA
    ZCBLENDM5(JL)=ZCBLENDM5(JL)&
           &+PFRTI(JL,JTILE)/(LOG(ZBLENDZ0/ZZ0MTI5(JL,JTILE)))**2
    ZCBLENDH5(JL)=ZCBLENDH5(JL)&
           &+PFRTI(JL,JTILE)/(LOG(ZBLENDZ0/ZZ0HTI5(JL,JTILE)))**2

  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  PZ0M5(JL)=ZBLENDZ0*EXP(-1._JPRB/SQRT(ZCBLENDM5(JL)))
  PZ0H5(JL)=ZBLENDZ0*EXP(-1._JPRB/SQRT(ZCBLENDH5(JL)))
ENDDO
! Because of z0m avg below, this must be placed here.
! It can go with other z0*tiw parameters if z0m avg is removed.
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
      PZ0MTIW5(JL,JTILE)=ZZ0MTI5(JL,JTILE)
  ENDDO
ENDDO

ZZ0MTI55(KIDIA:KFDIA,1:KTILES)=ZZ0MTI5(KIDIA:KFDIA,1:KTILES)
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    ZZ0MTI5(JL,JTILE)=PZ0M5(JL)
  ENDDO
ENDDO
!**DO JL=KIDIA,KFDIA
!**  JTILE=IFRMAX(JL)
!**  PZ0M5(JL) = ZZ0MTI5(JL,JTILE)
!**  PZ0H5(JL) = ZZ0HTI5(JL,JTILE)
!**ENDDO


!     ------------------------------------------------------------------

!*         2.     SURFACE BOUNDARY CONDITIONS FOR T AND Q
!                 ---------------------------------------

!    2.1 Albedo

ZALB5(KIDIA:KFDIA)=PFRTI(KIDIA:KFDIA,1)*PALBTI5(KIDIA:KFDIA,1)&
 & +PFRTI(KIDIA:KFDIA,2)*PALBTI5(KIDIA:KFDIA,2)&
 & +PFRTI(KIDIA:KFDIA,3)*PALBTI5(KIDIA:KFDIA,3)&
 & +PFRTI(KIDIA:KFDIA,4)*PALBTI5(KIDIA:KFDIA,4)&
 & +PFRTI(KIDIA:KFDIA,5)*PALBTI5(KIDIA:KFDIA,5)&
 & +PFRTI(KIDIA:KFDIA,6)*PALBTI5(KIDIA:KFDIA,6)&
 & +PFRTI(KIDIA:KFDIA,7)*PALBTI5(KIDIA:KFDIA,7)&
 & +PFRTI(KIDIA:KFDIA,8)*PALBTI5(KIDIA:KFDIA,8)

IF (LEURBAN) THEN
 ZALB5(KIDIA:KFDIA)=ZALB5(KIDIA:KFDIA)+PFRTI(KIDIA:KFDIA,10)*PALBTI5(KIDIA:KFDIA,10)
ENDIF

ZSSRFL15(KIDIA:KFDIA) = 0.0_JPRB

LLHISSR(KIDIA:KFDIA)=.FALSE.
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
! Disaggregate solar flux but limit to 700 W/m2 (due to inconsistency
!  with albedo)
    PSSRFLTI5(JL,JTILE) = ((1.0_JPRB-PALBTI5(JL,JTILE))&
     & /(1.0_JPRB-ZALB5(JL)))*PSSRFL5(JL)
    ZPSSRFLTI15(JL,JTILE) = PSSRFLTI5(JL,JTILE)
    IF (PSSRFLTI5(JL,JTILE) > 700._JPRB) THEN
      LLHISSR(JL)=.TRUE.
      PSSRFLTI5(JL,JTILE) = 700._JPRB
    ENDIF
    ZPSSRFLTI25(JL,JTILE) = PSSRFLTI5(JL,JTILE)

! Compute averaged net solar flux after limiting to 700 W/m2
    ZSSRFL15(JL) = ZSSRFL15(JL)&
     & + PFRTI(JL,JTILE)*PSSRFLTI5(JL,JTILE)
  ENDDO
ENDDO

DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    IF (LLHISSR(JL)) THEN
      PSSRFLTI5(JL,JTILE) = PSSRFLTI5(JL,JTILE)*PSSRFL5(JL)/ZSSRFL15(JL)
    ENDIF
    ZSRFD5(JL) = PSSRFLTI5(JL,JTILE)/(1.0_JPRB-PALBTI5(JL,JTILE))
    ZZSRFD5(JL,JTILE) = ZSRFD5(JL)
  ENDDO
  
  CALL VSURFS(KIDIA,KFDIA,KLON,KLEVS,JTILE,&
   & KTVL,KTVH,&
   & PLAIL, PLAIH,&
   & PTMLEV5  ,PQMLEV5 ,PAPHMS5 ,&
   & PTSKTI5(:,JTILE)  ,PWSAM1M5,PTSAM1M5,KSOTY,&
   & ZSRFD5, ZRAQTI5(:,JTILE)   ,&
   & PSSDP2, PSSDP3, YDCST    ,YDVEG   ,YDSOIL,&
   & ZQSATI5(:,JTILE)  ,PQSTI5(:,JTILE)   ,PDQSTI5(:,JTILE) ,&
   & ZWETB5, ZPCPTSTI5(:,JTILE), ZWETL5 , ZWETH5, ZWETHS5 )  
ENDDO


!*         3.     EXCHANGE COEFFICIENTS
!                 ---------------------

!*         3.1  SURFACE EXCHANGE COEFFICIENTS


DO JTILE=1,KTILES
  CALL VEXCSS(KIDIA,KFDIA,KLON,PTSTEP,PRVDIFTS,&
   & PUMLEV5,PVMLEV5,PTMLEV5,PQMLEV5,PAPHMS5,PGEOMLEV5,PCPTGZLEV5,&
   & ZPCPTSTI5(:,JTILE),ZQSATI5(:,JTILE) ,&
   & ZZ0MTI5(:,JTILE) ,ZZ0HTI5(:,JTILE) ,&
   & ZZ0QTI5(:,JTILE) ,ZBUOMTI5(:,JTILE),&
   & PUCURR5,PVCURR5,&
   & YDCST            ,YDEXC,&
   & ZCFMTI5(:,JTILE) ,PCFHTI5(:,JTILE) ,&
   & PCFQTI5(:,JTILE))
ENDDO


!*         3.2  EQUIVALENT EVAPOTRANSPIRATION EFFICIENCY COEFFICIENT

DO JTILE=1,KTILES
  IF     (JTILE == 1) THEN
    ZTSA5(KIDIA:KFDIA,JTILE)=PSST(KIDIA:KFDIA)
  ELSEIF (JTILE == 2) THEN
    ZTSA5(KIDIA:KFDIA,JTILE)=PTICE5(KIDIA:KFDIA)
  ELSEIF (JTILE == 5 .OR. JTILE == 7) THEN
    ZTSA5(KIDIA:KFDIA,JTILE)=PTSNOW5(KIDIA:KFDIA)
  ELSE
    ZTSA5(KIDIA:KFDIA,JTILE)=PTSAM1M5(KIDIA:KFDIA,1)
  ENDIF
  CALL VEVAPS(KIDIA,KFDIA,KLON,PTSTEP,PRVDIFTS,JTILE,&
   & PWLMX5 ,PTMLEV5 ,PQMLEV5 ,PAPHMS5,PTSKTI5(:,JTILE),ZTSA5(:,JTILE),&
   & PQSTI5(:,JTILE),PCFQTI5(:,JTILE),ZWETB5,ZWETL5,ZWETH5,ZWETHS5,&
   & YDCST          ,YDVEG           ,&
   & PCPTSTI5(:,JTILE),PCSATTI5(:,JTILE),PCAIRTI5(:,JTILE),&
   & ZCSNW5)  
ENDDO


!          COMPUTE SNOW EVAPORATION FROM BELOW TREES i.e. TILE 7

IF (LDSURF2) THEN

! Note the use of qsat(Tsnow), rather than tile 7 skin. Skin T7 is a
! canopy temperature, definitely not what is desirable. Skin T5 can go
! up (and down ..) freely, not really what we want. The use of
! qsat (Tsnow) is tantamount to neglecting the skin effect there.

  DO JL=KIDIA,KFDIA
!    ZQSSN15(JL) = FOEEW(PTSNOW5(JL))/PAPHMS5(JL)
    IF (PFRTI(JL,7) > 0.0_JPRB) THEN
      IF (PTSNOW5(JL) > RTT) THEN
        ZDIV15(JL) = 1.0_JPRB/(PTSNOW5(JL)-R4LES)
        Z3S5(JL) = R3LES*(PTSNOW5(JL)-RTT)*ZDIV15(JL)
      ELSE
        ZDIV15(JL) = 1.0_JPRB/(PTSNOW5(JL)-R4IES)
        Z3S5(JL) = R3IES*(PTSNOW5(JL)-RTT)*ZDIV15(JL)
      ENDIF
      Z4S5(JL) = EXP(Z3S5(JL))
      ZDIV25(JL) = 1.0_JPRB/PAPHMS5(JL)
      ZQSSN15(JL) = (R2ES*Z4S5(JL))*ZDIV25(JL)
      ZCOR5(JL) = 1.0_JPRB/(1.0_JPRB-RETV  *ZQSSN15(JL))
      ZQSSN5(JL)= ZQSSN15(JL)*ZCOR5(JL)
      PEVAPSNW5(JL) = &
       & ZCONS1*PCFQTI5(JL,7)*ZCSNW5(JL)*(PQMLEV5(JL)-ZQSSN5(JL))
    ELSE
      PEVAPSNW5(JL) = 0.0_JPRB
    ENDIF
  ENDDO
ELSE

  DO JL=KIDIA,KFDIA
    ZQSSN15(JL) = FOEEW(PTSNOW5(JL))/PAPHMS5(JL)
    ZCOR5(JL) = 1.0_JPRB/(1.0_JPRB-RETV  *ZQSSN15(JL))
    ZQSSN5(JL)= ZQSSN15(JL)*ZCOR5(JL)
    PEVAPSNW5(JL) = &
     & ZCONS1*PCFQTI5(JL,7)*ZCSNW5(JL)*(PQMLEV5(JL)-ZQSSN5(JL))
  ENDDO
ENDIF

!          3.2A    COMPUTE SURFACE FLUXES, WEIGHTED AVERAGE OVER TILES
!                  ------- ------- ------- -------- ------- ---- -----

PCFMLEV5(KIDIA:KFDIA) = 0.0_JPRB
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    PCFMLEV5(JL) = PCFMLEV5(JL)+PFRTI(JL,JTILE)*ZCFMTI5(JL,JTILE)
  ENDDO
ENDDO

!*         4.  Preparation for "POST-PROCESSING" of surface weather parameters

!          POST-PROCESSING WITH LOCAL INSTEAD OF EFFECTIVE
!          SURFACE ROUGHNESS LENGTH. THE LOCAL ONES ARE FOR
!          WMO-TYPE WIND STATIONS I.E. OPEN TERRAIN WITH GRASS

ZZ0MWMO=0.03_JPRB
ZZ0HWMO=0.003_JPRB
!* similar to non-linear:
DO JL=KIDIA,KFDIA
  !*JTILE=IFRMAX(JL)
  !*IF (JTILE  >  2.AND. ZZ0MTI5(JL,JTILE)  >  ZZ0MWMO) THEN
  IF (PZ0M5(JL)  >  ZZ0MWMO) THEN
    PZ0MW5(JL) = ZZ0MWMO 
    !*PZ0HW5(JL) = ZZ0HWMO
    !*PZ0QW5(JL) = ZZ0HWMO
  ELSE
    PZ0MW5(JL) = PZ0M5(JL)
    !*PZ0MW5(JL) = ZZ0MTI5(JL,JTILE)
    !*PZ0HW5(JL) = ZZ0HTI5(JL,JTILE)
    !*PZ0QW5(JL) = ZZ0QTI5(JL,JTILE)
  ENDIF
ENDDO

DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    ZZQSATI55(JL,JTILE)=PQMLEV5(JL)*(1.0_JPRB-PCAIRTI5(JL,JTILE)) &
     & + PCSATTI5(JL,JTILE)*PQSTI5(JL,JTILE)
    IF (ZZQSATI55(JL,JTILE) < 1.0E-12_JPRB) THEN
      ZZQSATI5(JL,JTILE) = 1.0E-12_JPRB
    ELSE
      ZZQSATI5(JL,JTILE) = ZZQSATI55(JL,JTILE)
    ENDIF
  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  !*JTILE=IFRMAX(JL)
  JTILE=IFRLMAX(JL)
  PZ0HW5(JL)=ZZ0HTI5(JL,JTILE)
  PZ0QW5(JL)=ZZ0QTI5(JL,JTILE)
  PCPTSPP5(JL) = PCPTSTI5(JL,JTILE)
  PQSAPP5(JL) = ZZQSATI5(JL,JTILE)
  PBUOMPP5(JL) = ZBUOMTI5(JL,JTILE)
ENDDO
!          PP: STORE TILE-DEPENDENT QUANTITIES FOR T2M/D2M per TILE CALCULATION 
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    PZ0HTIW5(JL,JTILE)=ZZ0HTI5(JL,JTILE)
    PZ0QTIW5(JL,JTILE)=ZZ0QTI5(JL,JTILE)
    PBUOMTI5(JL,JTILE)=ZBUOMTI5(JL,JTILE)
    PQSAPPTI5(JL,JTILE)=ZZQSATI5(JL,JTILE)
    PCPTSPPTI5(JL,JTILE)=PCPTSTI5(JL,JTILE)
  ENDDO
ENDDO
!---------------------------------------------------------------------------

!*                  -------- ADJOINT COMPUTATIONS --------

!---------------------------------------------------------------------------

!*         5.     INITIALIZATION TO ZERO OF LOCAL VARIABLES


ZFRMAX (:) = 0.0_JPRB
ZALB   (:) = 0.0_JPRB
ZSSRFL1(:) = 0.0_JPRB
ZSRFD  (:) = 0.0_JPRB
ZWETL  (:) = 0.0_JPRB
ZWETH  (:) = 0.0_JPRB
ZWETHS (:) = 0.0_JPRB
ZWETB  (:) = 0.0_JPRB
ZTSA   (:) = 0.0_JPRB
ZCSNW  (:) = 0.0_JPRB

ZCBLENDM(:)=0.0_JPRB
ZCBLENDH(:)=0.0_JPRB

ZZ0MTI (:,:) = 0.0_JPRB
ZZ0HTI (:,:) = 0.0_JPRB
ZZ0QTI (:,:) = 0.0_JPRB
ZBUOMTI(:,:) = 0.0_JPRB
ZZDLTI (:,:) = 0.0_JPRB
ZRAQTI (:,:) = 0.0_JPRB
ZQSATI (:,:) = 0.0_JPRB
ZCFMTI (:,:) = 0.0_JPRB
ZZQSATI(:,:) = 0.0_JPRB

!*         4.  Preparation for "POST-PROCESSING" of surface weather parameters

!          POST-PROCESSING WITH LOCAL INSTEAD OF EFFECTIVE
!          SURFACE ROUGHNESS LENGTH. THE LOCAL ONES ARE FOR
!          WMO-TYPE WIND STATIONS I.E. OPEN TERRAIN WITH GRASS

!          PP: STORE TILE-DEPENDENT QUANTITIES FOR T2M/D2M per TILE CALCULATION 
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    PCPTSTI(JL,JTILE)=PCPTSTI(JL,JTILE)+PCPTSPPTI(JL,JTILE)
    PCPTSPPTI(JL,JTILE)=0.0_JPRB
    ZZQSATI(JL,JTILE)=ZZQSATI(JL,JTILE)+PQSAPPTI(JL,JTILE)
    PQSAPPTI(JL,JTILE)=0.0_JPRB
    ZBUOMTI(JL,JTILE)=ZBUOMTI(JL,JTILE)+PBUOMTI(JL,JTILE)
    PBUOMTI(JL,JTILE)=0.0_JPRB
    ZZ0QTI(JL,JTILE)=ZZ0QTI(JL,JTILE)+PZ0QTIW(JL,JTILE)
    PZ0QTIW(JL,JTILE)=0.0_JPRB
    ZZ0HTI(JL,JTILE)=ZZ0HTI(JL,JTILE)+PZ0HTIW(JL,JTILE)
    PZ0HTIW(JL,JTILE)=0.0_JPRB
  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  !*JTILE=IFRMAX(JL)
  JTILE=IFRLMAX(JL)
  ZBUOMTI(JL,JTILE) = ZBUOMTI(JL,JTILE)+PBUOMPP(JL)
  PBUOMPP(JL) = 0.0_JPRB
  ZZQSATI(JL,JTILE) = ZZQSATI(JL,JTILE)+PQSAPP(JL)
  PQSAPP(JL) = 0.0_JPRB
  PCPTSTI(JL,JTILE) = PCPTSTI(JL,JTILE)+PCPTSPP(JL)
  PCPTSPP(JL) = 0.0_JPRB
  ZZ0QTI(JL,JTILE)=ZZ0QTI(JL,JTILE)+PZ0QW(JL)
  PZ0QW(JL)=0.0_JPRB
  ZZ0HTI(JL,JTILE)=ZZ0HTI(JL,JTILE)+PZ0HW(JL)
  PZ0HW(JL)=0.0_JPRB
ENDDO

DO JTILE=1,KTILES
  DO JL = KIDIA, KFDIA
    IF (ZZQSATI55(JL,JTILE) < 1.0E-12_JPRB) THEN
      ZZQSATI (JL,JTILE) = 0.0_JPRB
    ENDIF

    PQMLEV(JL) = PQMLEV(JL)+ZZQSATI (JL,JTILE)*(1.0_JPRB-PCAIRTI5(JL,JTILE))
    PCAIRTI (JL,JTILE) = PCAIRTI (JL,JTILE)-ZZQSATI (JL,JTILE)*PQMLEV5(JL)
    PQSTI (JL,JTILE) = PQSTI (JL,JTILE) &
     & + ZZQSATI (JL,JTILE)*PCSATTI5(JL,JTILE)
    PCSATTI (JL,JTILE) = PCSATTI (JL,JTILE) &
     & + ZZQSATI (JL,JTILE)*PQSTI5(JL,JTILE)
    ZZQSATI (JL,JTILE) = 0.0_JPRB
  ENDDO
ENDDO

DO JL=KIDIA,KFDIA
  !*JTILE=IFRMAX(JL)
  !*IF (JTILE  <=  2.AND. ZZ0MTI5(JL,JTILE)  <=  ZZ0MWMO) THEN
    !*ZZ0QTI(JL,JTILE) = ZZ0QTI(JL,JTILE)+PZ0QW(JL)
    !*ZZ0HTI(JL,JTILE) = ZZ0HTI(JL,JTILE)+PZ0HW(JL)
    !*ZZ0MTI(JL,JTILE) = ZZ0MTI(JL,JTILE)+PZ0MW(JL)
  IF (PZ0M5(JL)  <=  ZZ0MWMO) THEN
    PZ0M(JL)=PZ0M(JL)+PZ0MW (JL)
  ENDIF
  PZ0MW(JL) = 0.0_JPRB
  !*PZ0HW(JL) = 0.0_JPRB
  !*PZ0QW(JL) = 0.0_JPRB
ENDDO

!          3.2A    COMPUTE SURFACE FLUXES, WEIGHTED AVERAGE OVER TILES
!                  ------- ------- ------- -------- ------- ---- -----

DO JTILE=KTILES,1,-1
  DO JL=KIDIA,KFDIA
    ZCFMTI(JL,JTILE) = ZCFMTI(JL,JTILE)+PFRTI(JL,JTILE)*PCFMLEV(JL)
  ENDDO
ENDDO
PCFMLEV (KIDIA:KFDIA) = 0.0_JPRB

!*         3.2     EQUIVALENT EVAPOTRANSPIRATION EFFICIENCY COEFFICIENT

IF (LDSURF2) THEN

!        COMPUTE SNOW EVAPORATION FROM BELOW TREES i.e. TILE 7
  DO JL=KIDIA,KFDIA
    ZCOR = 0.0_JPRB
    ZQSSN = 0.0_JPRB
    Z3S = 0.0_JPRB
    Z4S = 0.0_JPRB

    IF (PFRTI(JL,7) > 0.0_JPRB) THEN
      PCFQTI(JL,7) = PCFQTI(JL,7)+ZCONS1*ZCSNW5(JL) &
       & * (PQMLEV5(JL)-ZQSSN5(JL))*PEVAPSNW(JL)
      ZCSNW(JL) = ZCSNW(JL)+ZCONS1*PCFQTI5(JL,7) &
       & * (PQMLEV5(JL)-ZQSSN5(JL))*PEVAPSNW(JL)
      PQMLEV(JL) = PQMLEV(JL)+ZCONS1*ZCSNW5(JL)*PCFQTI5(JL,7) &
       & * PEVAPSNW(JL)
      ZQSSN = ZQSSN-ZCONS1*ZCSNW5(JL)*PCFQTI5(JL,7)*PEVAPSNW (JL)
      PEVAPSNW (JL)=0.0_JPRB

      ZCOR  = ZCOR+ZQSSN15(JL)*ZQSSN
      ZQSSN = ZCOR5(JL)*ZQSSN
      ZQSSN = ZQSSN+RETV * ZCOR/(1.0_JPRB-RETV*ZQSSN15(JL))**2

      Z4S = Z4S+R2ES*PAPHMS5(JL)*ZDIV25(JL)*ZDIV25(JL)*ZQSSN
      PAPHMS(JL) = PAPHMS(JL)-R2ES*Z4S5(JL)*ZDIV25(JL)*ZDIV25(JL)*ZQSSN
      Z3S = Z3S+Z4S5(JL)*Z4S
      IF (PTSNOW5(JL) > RTT) THEN
        PTSNOW(JL) = PTSNOW(JL)+R3LES*(RTT-R4LES)*ZDIV15(JL)*ZDIV15(JL)*Z3S
      ELSE
        PTSNOW(JL) = PTSNOW(JL)+R3IES*(RTT-R4IES)*ZDIV15(JL)*ZDIV15(JL)*Z3S
      ENDIF
    ELSE
      PEVAPSNW (JL) = 0.0_JPRB
    ENDIF
  ENDDO
ELSE

  DO JL=KIDIA,KFDIA
    ZCOR = 0.0_JPRB
    ZQSSN = 0.0_JPRB

    PCFQTI(JL,7) = PCFQTI(JL,7)+ZCONS1*ZCSNW5(JL) &
     & * (PQMLEV5(JL)-ZQSSN5(JL))*PEVAPSNW(JL)
    ZCSNW(JL) = ZCSNW(JL)+ZCONS1*PCFQTI5(JL,7) &
     & * (PQMLEV5(JL)-ZQSSN5(JL))*PEVAPSNW(JL)
    PQMLEV(JL) = PQMLEV(JL)+ZCONS1*ZCSNW5(JL)*PCFQTI5(JL,7) &
     & * PEVAPSNW(JL)
    ZQSSN = ZQSSN-ZCONS1*ZCSNW5(JL)*PCFQTI5(JL,7)*PEVAPSNW (JL)
    PEVAPSNW (JL)=0.0_JPRB

    ZCOR  = ZCOR+ZQSSN15(JL)*ZQSSN
    ZQSSN = ZCOR5(JL)*ZQSSN
    ZQSSN = ZQSSN+RETV * ZCOR/(1.0_JPRB-RETV*ZQSSN15(JL))**2
    PAPHMS(JL)=PAPHMS(JL)-(FOEEW(PTSNOW5(JL))/PAPHMS5(JL)**2)*ZQSSN
  ENDDO
ENDIF

IF (LDNOPERT) THEN
  DO JTILE=1,KTILES

! perturbations are put to zero

    PCPTSTI(KIDIA:KFDIA,JTILE)=0.0_JPRB
    PCSATTI(KIDIA:KFDIA,JTILE)=0.0_JPRB
    PCAIRTI(KIDIA:KFDIA,JTILE)=0.0_JPRB
    ZCSNW(KIDIA:KFDIA)=0.0_JPRB
  ENDDO
ELSE
  DO JTILE=1,KTILES
    CALL VEVAPSAD(KIDIA,KFDIA,KLON,PTSTEP,PRVDIFTS,JTILE,&
     & PWLMX5,PTMLEV5,PQMLEV5,PAPHMS5,PTSKTI5(:,JTILE) ,ZTSA5(:,JTILE),&
     & PQSTI5(:,JTILE) ,PCFQTI5(:,JTILE) ,ZWETB5,ZWETL5,ZWETH5,ZWETHS5,&
     & YDCST           ,YDVEG,&
     & PCPTSTI5(:,JTILE),PCSATTI5(:,JTILE),PCAIRTI5(:,JTILE),&
     & ZCSNW5,&
     & PTMLEV  ,PQMLEV ,PAPHMS  ,PTSKTI(:,JTILE)  ,ZTSA ,&
     & PQSTI(:,JTILE)  ,PCFQTI(:,JTILE)  ,ZWETB ,ZWETL ,ZWETH ,ZWETHS ,&
     & PCPTSTI (:,JTILE),PCSATTI (:,JTILE),PCAIRTI (:,JTILE),&
     & ZCSNW )

     IF     (JTILE == 1) THEN
      ZTSA(KIDIA:KFDIA)=0.0_JPRB
    ELSEIF (JTILE == 2) THEN
      PTICE(KIDIA:KFDIA) = PTICE(KIDIA:KFDIA)+ZTSA(KIDIA:KFDIA)
      ZTSA(KIDIA:KFDIA)=0.0_JPRB
    ELSEIF (JTILE == 5 .OR. JTILE == 7) THEN
      PTSNOW(KIDIA:KFDIA) = PTSNOW(KIDIA:KFDIA)+ZTSA(KIDIA:KFDIA)
      ZTSA(KIDIA:KFDIA)=0.0_JPRB
    ELSE
      PTSAM1M(KIDIA:KFDIA,1) = PTSAM1M(KIDIA:KFDIA,1)+ZTSA(KIDIA:KFDIA)
      ZTSA(KIDIA:KFDIA)=0.0_JPRB
    ENDIF
  ENDDO
ENDIF

!*         3.1  SURFACE EXCHANGE COEFFICIENTS

IF (LDNOPERT) THEN
  DO JTILE=1,KTILES

! perturbations are put to zero
    ZCFMTI(KIDIA:KFDIA,JTILE)=0.0_JPRB
    PCFHTI(KIDIA:KFDIA,JTILE)=0.0_JPRB
    PCFQTI(KIDIA:KFDIA,JTILE)=0.0_JPRB
  ENDDO
ELSE

  IF (LDREGSF) THEN
    ! Regularization of wet skin tile perturbation in low wind situations. 
    DO JL=KIDIA,KFDIA
      IF (SQRT(PUMLEV5(JL)**2 + PVMLEV5(JL)**2) < 1.5_JPRB) PCFQTI(JL,3)=0.0_JPRB
    ENDDO
  ENDIF

  DO JTILE=1,KTILES
    CALL VEXCSSAD(KIDIA,KFDIA,KLON,PTSTEP,PRVDIFTS,&
     & LDKPERTS, LDREGBUOF,&
     & PUMLEV5,PVMLEV5,PTMLEV5,PQMLEV5,PAPHMS5,PGEOMLEV5,PCPTGZLEV5,&
     & ZPCPTSTI5(:,JTILE),ZQSATI5(:,JTILE) ,&
     & ZZ0MTI5(:,JTILE) ,ZZ0HTI5(:,JTILE) ,&
     & ZZ0QTI5(:,JTILE) ,ZBUOMTI5(:,JTILE),&
     & PUCURR5,PVCURR5,&
     & YDCST            ,YDEXC            ,&
     & ZCFMTI5(:,JTILE) ,PCFHTI5(:,JTILE) ,&
     & PCFQTI5(:,JTILE) ,&
     & PUMLEV ,PVMLEV ,PTMLEV ,PQMLEV ,PAPHMS ,PGEOMLEV ,PCPTGZLEV ,&
     & PCPTSTI(:,JTILE) ,ZQSATI(:,JTILE)  ,&
     & ZZ0MTI(:,JTILE)  ,ZZ0HTI(:,JTILE)  ,&
     & ZZ0QTI(:,JTILE)  ,ZBUOMTI(:,JTILE) ,&
     & ZCFMTI(:,JTILE)  ,PCFHTI(:,JTILE)  ,&
     & PCFQTI(:,JTILE) )
  ENDDO
ENDIF

!     ------------------------------------------------------------------

!*         2.     SURFACE BOUNDARY CONDITIONS FOR T AND Q
!                 ---------------------------------------
DO JTILE=KTILES,1,-1
  IF (LDNOPERT) THEN

! perturbations are put to zero

    ZQSATI (KIDIA:KFDIA,JTILE) = 0.0_JPRB
    PQSTI  (KIDIA:KFDIA,JTILE) = 0.0_JPRB
    PDQSTI (KIDIA:KFDIA,JTILE) = 0.0_JPRB
    PCPTSTI(KIDIA:KFDIA,JTILE) = 0.0_JPRB
    ZWETB  (KIDIA:KFDIA) = 0.0_JPRB
    ZWETL  (KIDIA:KFDIA) = 0.0_JPRB
    ZWETH  (KIDIA:KFDIA) = 0.0_JPRB
    ZWETHS (KIDIA:KFDIA) = 0.0_JPRB
  ELSE
    CALL VSURFSAD(KIDIA,KFDIA,KLON,KLEVS,JTILE,&
     & KTVL,KTVH,&
     & PLAIL, PLAIH,&
     & PTMLEV5  ,PQMLEV5 ,PAPHMS5 ,&
     & PTSKTI5(:,JTILE)  ,PWSAM1M5,PTSAM1M5 , KSOTY,&
     & ZZSRFD5(:,JTILE),  ZRAQTI5(:,JTILE)  ,&
     & PSSDP2  ,PSSDP3   ,YDCST    ,YDVEG   ,YDSOIL   ,&
     & ZQSATI5(:,JTILE)  ,PQSTI5(:,JTILE)   ,PDQSTI5(:,JTILE) ,&
     & ZWETB5, ZPCPTSTI5(:,JTILE)  , ZWETL5 , ZWETH5, ZWETHS5,&
     & PTMLEV   ,PQMLEV  ,PAPHMS  ,&
     & PTSKTI(:,JTILE)   ,PWSAM1M ,PTSAM1M ,&
     & ZSRFD ,  ZRAQTI(:,JTILE)   , ZQSATI(:,JTILE) ,&
     & PQSTI(:,JTILE)    ,PDQSTI(:,JTILE)  ,&
     & ZWETB , PCPTSTI(:,JTILE)   , ZWETL  , ZWETH , ZWETHS )
  ENDIF

  DO JL=KIDIA,KFDIA
    PSSRFLTI(JL,JTILE) = PSSRFLTI(JL,JTILE) &
     & + ZSRFD(JL)/(1.0_JPRB-PALBTI5(JL,JTILE))
    PALBTI(JL,JTILE) = PALBTI(JL,JTILE)+ZSRFD(JL)*PSSRFLTI5(JL,JTILE) &
     & / (1.0_JPRB-PALBTI5(JL,JTILE))**2
    ZSRFD(JL)=0.0_JPRB

    IF (LLHISSR(JL)) THEN
      PSSRFL(JL) = PSSRFL(JL)+ZPSSRFLTI25(JL,JTILE)*PSSRFLTI(JL,JTILE) &
       & / ZSSRFL15(JL)
      ZSSRFL1(JL) = ZSSRFL1(JL)-(ZPSSRFLTI25(JL,JTILE)*PSSRFL5(JL) &
       & / ZSSRFL15(JL)**2)*PSSRFLTI(JL,JTILE)
      PSSRFLTI(JL,JTILE) = PSSRFLTI(JL,JTILE)*PSSRFL5(JL)/ZSSRFL15(JL)
    ENDIF
  ENDDO
ENDDO

DO JTILE=KTILES,1,-1
  DO JL=KIDIA,KFDIA
! Compute averaged net solar flux after limiting to 700 W/m2
    PSSRFLTI(JL,JTILE)=PSSRFLTI(JL,JTILE)+PFRTI(JL,JTILE)*ZSSRFL1(JL)

! Disaggregate solar flux but limit to 700 W/m2 (due to inconsistency 
! with albedo)

    IF (ZPSSRFLTI15(JL,JTILE) > 700._JPRB) THEN
      PSSRFLTI(JL,JTILE)=0._JPRB
    ENDIF
    PSSRFL(JL) = PSSRFL(JL) &
     & + ((1.0_JPRB-PALBTI5(JL,JTILE)) &
     & / (1.0_JPRB-ZALB5(JL)))*PSSRFLTI(JL,JTILE)
    PALBTI(JL,JTILE) = PALBTI(JL,JTILE) &
     & - (PSSRFL5(JL)/(1.0_JPRB-ZALB5(JL)))*PSSRFLTI(JL,JTILE)
    ZALB(JL) = ZALB(JL)+&
     & (PSSRFL5(JL)*(1.0_JPRB-PALBTI5(JL,JTILE))&
     & /(1.0_JPRB-ZALB5(JL))**2)*PSSRFLTI(JL,JTILE)
    PSSRFLTI(JL,JTILE) = 0.0_JPRB
  ENDDO
ENDDO

ZSSRFL1 (KIDIA:KFDIA) = 0.0_JPRB

PALBTI(KIDIA:KFDIA,1) = PALBTI(KIDIA:KFDIA,1) &
 & + PFRTI(KIDIA:KFDIA,1)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,2) = PALBTI(KIDIA:KFDIA,2) &
 & + PFRTI(KIDIA:KFDIA,2)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,3) = PALBTI(KIDIA:KFDIA,3) &
 & + PFRTI(KIDIA:KFDIA,3)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,4) = PALBTI(KIDIA:KFDIA,4) &
 & + PFRTI(KIDIA:KFDIA,4)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,5) = PALBTI(KIDIA:KFDIA,5) &
 & + PFRTI(KIDIA:KFDIA,5)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,6) = PALBTI(KIDIA:KFDIA,6) &
 & + PFRTI(KIDIA:KFDIA,6)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,7) = PALBTI(KIDIA:KFDIA,7) &
 & + PFRTI(KIDIA:KFDIA,7)*ZALB(KIDIA:KFDIA)
PALBTI(KIDIA:KFDIA,8) = PALBTI(KIDIA:KFDIA,8) &
 & + PFRTI(KIDIA:KFDIA,8)*ZALB(KIDIA:KFDIA)
IF (LEURBAN) THEN
PALBTI(KIDIA:KFDIA,10) = PALBTI(KIDIA:KFDIA,10) &
 & + PFRTI(KIDIA:KFDIA,10)*ZALB(KIDIA:KFDIA)
ENDIF
ZALB(KIDIA:KFDIA)=0.0_JPRB

!*         1.3  FIND DOMINANT SURFACE TYPE parameters for postprocessing
!**Following not used anymore
!**DO JL=KIDIA,KFDIA
!**  JTILE=IFRMAX(JL)
!**  ZZ0HTI(JL,JTILE)=ZZ0HTI(JL,JTILE)+PZ0H(JL)
!**  PZ0H(JL)=0.0_JPRB
!**  ZZ0MTI(JL,JTILE)=ZZ0MTI(JL,JTILE)+PZ0M(JL)
!**  PZ0M(JL)=0.0_JPRB
!**ENDDO
!* Use avg z0m for all tiles, consistent with non linear
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
    PZ0M(JL)=PZ0M(JL)+ZZ0MTI(JL,JTILE)
    ZZ0MTI(JL,JTILE)=0.0_JPRB
  ENDDO
ENDDO
! Because of z0m avg above, this must be placed here.
! It can go with other z0*tiw parameters if z0m avg is removed.
DO JTILE=1,KTILES
  DO JL=KIDIA,KFDIA
      ZZ0MTI(JL,JTILE)=ZZ0MTI(JL,JTILE)+PZ0MTIW(JL,JTILE)
      PZ0MTIW(JL,JTILE)=0.0_JPRB
  ENDDO
ENDDO
!* Use tile average (log) Z0 for M and H, consistent with non-linear
DO JL=KIDIA,KFDIA
 ZCBLENDH(JL)= ZCBLENDH(JL)+PZ0H(JL)*&
             & ZBLENDZ0*EXP(-1._JPRB/SQRT(ZCBLENDH5(JL)))/(2._JPRB*ZCBLENDH5(JL)**(3._JPRB/2._JPRB))
 PZ0H(JL)=0.0_JPRB
 ZCBLENDM(JL)= ZCBLENDM(JL)+PZ0M(JL)*&
             & ZBLENDZ0*EXP(-1._JPRB/SQRT(ZCBLENDM5(JL)))/(2._JPRB*ZCBLENDM5(JL)**(3._JPRB/2._JPRB))
  PZ0M(JL)=0.0_JPRB

ENDDO
DO JTILE=2,KTILES
  DO JL=KIDIA,KFDIA
    ZZ0HTI(JL,JTILE)= ZZ0HTI(JL,JTILE)+ZCBLENDH(JL)*&
                    & 2._JPRB*PFRTI(JL,JTILE)/(ZZ0HTI5(JL,JTILE)*(LOG(ZBLENDZ0/ZZ0HTI5(JL,JTILE)))**3)
    ZCBLENDH(JL)=ZCBLENDH(JL)
    ZZ0MTI(JL,JTILE)= ZZ0MTI(JL,JTILE)+ZCBLENDM(JL)*&
                    & 2._JPRB*PFRTI(JL,JTILE)/(ZZ0MTI5(JL,JTILE)*(LOG(ZBLENDZ0/ZZ0MTI5(JL,JTILE)))**3)
    ZCBLENDM(JL)=ZCBLENDM(JL)

  ENDDO
ENDDO

ZZ0HTI(KIDIA:KFDIA,1)=ZZ0HTI(KIDIA:KFDIA,1)+ZCBLENDH(KIDIA:KFDIA)*2._JPRB*PFRTI(KIDIA:KFDIA,1)/&
                     &(ZZ0HTI5(KIDIA:KFDIA,1)*(LOG(ZBLENDZ0/ZZ0HTI5(KIDIA:KFDIA,1)))**3)
ZCBLENDH(KIDIA:KFDIA)=0.0_JPRB
ZZ0MTI(KIDIA:KFDIA,1)=ZZ0MTI(KIDIA:KFDIA,1)+ZCBLENDM(KIDIA:KFDIA)*2._JPRB*PFRTI(KIDIA:KFDIA,1)/&
           &(ZZ0MTI55(KIDIA:KFDIA,1)*(LOG(ZBLENDZ0/ZZ0MTI55(KIDIA:KFDIA,1)))**3)
ZCBLENDM(KIDIA:KFDIA)=0.0_JPRB

ZFRMAX(KIDIA:KFDIA)=0.0_JPRB

!*         1.2  UPDATE Z0

IF (LDNOPERT) THEN
  DO JTILE=1,KTILES

! perturbations are put to zero

    ZRAQTI(KIDIA:KFDIA,JTILE) = 0.0_JPRB
    ZZDLTI(KIDIA:KFDIA,JTILE) = 0.0_JPRB
    ZBUOMTI(KIDIA:KFDIA,JTILE)= 0.0_JPRB
    ZZ0QTI(KIDIA:KFDIA,JTILE) = 0.0_JPRB
    ZZ0HTI(KIDIA:KFDIA,JTILE) = 0.0_JPRB
    ZZ0MTI(KIDIA:KFDIA,JTILE) = 0.0_JPRB
  ENDDO
ELSE
  CALL VUPDZ0SAD(KIDIA,KFDIA,KLON,KTILES,KSTEP,&
   & KTVL, KTVH, PCVL, PCVH,PCUR,&
   & PUMLEV5 , PVMLEV5 ,&
   & PTMLEV5 , PQMLEV5 , PAPHMS5 , PGEOMLEV5,&
   & ZDSN5   ,&
   & PUSTRTI5, PVSTRTI5, PAHFSTI5, PEVAPTI5 ,&
   & PTSKTI5 , PCHAR   , PFRTI   ,&
   & PSSDP2  , YDCST   , YDEXC   ,YDVEG    ,YDFLAKE   , YDURB  ,&
   & ZZ0MTI5 , ZZ0HTI5 , ZZ0QTI5 , ZBUOMTI5 , ZZDLTI5, ZRAQTI5 ,&
   & PUMLEV  , PVMLEV  ,&
   & PTMLEV  , PQMLEV  , PAPHMS  , PGEOMLEV ,&
   & PUSTRTI , PVSTRTI , PAHFSTI , PEVAPTI  ,&
   & PTSKTI  , &
   & ZZ0MTI  , ZZ0HTI  , ZZ0QTI  , ZBUOMTI  , ZZDLTI , ZRAQTI, &
   & PUCURR5 , PVCURR5)
ENDIF

!*         1.1  ESTIMATE SURF.FL. FOR STEP 0
!*              (ASSUME NEUTRAL STRATIFICATION)

IF (KSTEP == 0) THEN
  DO JL=KIDIA,KFDIA
    PTSKTI(JL,1)=0.0_JPRB
  ENDDO
    
  DO JTILE=2,KTILES
    DO JL=KIDIA,KFDIA
      PTSKM1M(JL) = PTSKM1M(JL)+PTSKTI(JL,JTILE)
      PTSKTI(JL,JTILE) = 0.0_JPRB
    ENDDO
  ENDDO
ENDIF

END ASSOCIATE
IF (LHOOK) CALL DR_HOOK('SURFEXCDRIVERSAD_CTL_MOD:SURFEXCDRIVERSAD_CTL',1,ZHOOK_HANDLE)

END SUBROUTINE SURFEXCDRIVERSAD_CTL
END MODULE SURFEXCDRIVERSAD_CTL_MOD
